/*
 * @Author: gitee_com_zb
 * @Date: 2024-11-28 17:23:52
 * @LastEditors: gitee_com_zb
 * @LastEditTime: 2024-11-28 17:24:21
 * @FilePath: /algorithm/每日一题1.二分查找.cpp
 * @Description: 题目链接 https://www.nowcoder.com/share/jump/3018661641732785801196
 */

class BinarySearch {
  public:
    int getPos(vector<int> A, int n, int val) {
        // 二分--左端点模版
        if(n <= 0) return -1;
        int left = 0, right = n - 1, mid = 0;
        while(left < right) {
            mid = left + (right - left) / 2; 
            if(A[mid] < val) left = mid + 1;
            else right = mid;
        }
        return A[left] == val ? left : -1; 
    }
};